package com.timebank.websocket.pojo.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.websocket.Session;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 *  当前在线列表信息
 * @author shiliuyinzhen
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OnlineUser implements Serializable {

    private static final long serialVersionUID = 6239537958223115071L;

    /**
     * 用户ID
     */
    private String userId;

    /**
     * 用户名称
     */
    private String userName;

    /**
     * 用户会话 (使用该对象进行消息发送)
     */
    private Session session;

    /**
     * 连接时间
     */
    private String createTime;

    /**
     * @param userId   用户id
     * @param username 用户名称
     * @param username 用户头像
     * @param session  用户session 回话信息
     */
    public OnlineUser(String userId, String username,  Session session) {
        this.userId = userId;
        this.userName = username;
        this.session = session;
        //
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        this.createTime = df.format(LocalDateTime.now());
    }
}
